﻿using Mengsk.ProxyDelivery.Domain;
using Mengsk.ProxyDelivery.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Mengsk.ProxyDelivery.App.UI.Order
{
    /// <summary>
    /// OrderGoodsEditWindow.xaml 的交互逻辑
    /// </summary>
    public partial class OrderGoodsEditWindow : Window
    {
        public OrderGoods OrderGoods { get; set; }

        public OrderGoodsEditWindow()
        {
            InitializeComponent();
        }

        private string[] GetSize()
        {
            string[] ss = new string[] { "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "30", "31", "32", "33" };
            return ss;
        }

        private string[] GetEdtions()
        {
            string[] ss = new string[] { "  ", "升级", "单里", "绒里", "短毛", "厚毛", "皮里" };
            return ss;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                //读取颜色
                if (this.OrderGoods.NumberId > 0)
                {
                    var shoesSku = ServiceContainer.GetService<ShoesSkuService>().GetAllByField("shoesId", this.OrderGoods.NumberId, 0, 0);
                    var colors = shoesSku.Datas.Select(obj => obj.Color).Distinct().ToList();
                    this.cbbColors.ItemsSource = colors;
                }
                this.tbNumberId.Text = this.OrderGoods.NumberId.ToString();
                this.cbbSizes.ItemsSource = GetSize();
                this.cbbEditons.ItemsSource = GetEdtions();
                this.cbbColors.SelectedItem = this.OrderGoods.Color;
                this.cbbSizes.SelectedItem = this.OrderGoods.Size;
                this.cbbEditons.SelectedItem = this.OrderGoods.Edtion;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string color = this.cbbColors.Text.Trim();
                string size = this.cbbSizes.Text.Trim();
                string edtion = this.cbbEditons.Text.Trim();
                int numberId = int.Parse(this.tbNumberId.Text.Trim());
                if (string.IsNullOrWhiteSpace(color) || string.IsNullOrWhiteSpace(size))
                {
                    MessageBox.Show("颜色,尺码不能为空");
                    return;
                }
                ServiceContainer.GetService<OrderService>().ModifyOrderGoods(this.OrderGoods.OrderId, this.OrderGoods.Id, numberId, color, size, edtion);
                MessageBox.Show("修改成功");
                this.DialogResult = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
